<?php
/**
 * Created by PhpStorm.
 * User: taoyufang
 * Date: 17/12/05
 * Time: 16:52
 */

class TaskPrizeMapModel extends MY_Model{

    protected $table = 't_task_prize_map';

    public function __construct(){
        parent::__construct();
    }

    public function del_insert_prize($id='',$arr=array()){
        if(empty($id)){return '';}
        //删除任务id里的所有奖励
        $del=$this->del_data(array('task_id'=>$id));
//        echo $del;exit;
        if($del!==false){
            //为任务新加奖励
            if(!empty($arr)){
                foreach($arr as $k=>$v){
                    $arr_i[$k]=array('task_id'=>$id,'task_prize_id'=>$v['id']);
                }
                $this->db->insert_batch($this->table,$arr_i);
            }
        }
    }
    /**
     * 获取奖励列表
     * name: getList
     * @param string $like
     * @param int $page
     * @param int $pagesize
     * @return array
     * @Author:taiyang
     */
    public function getPrizeList($task_id=''){
        $sql="select * from ".$this->table." WHERE 1 ";

        if(!empty($task_id)){
            $sql .= " and `task_id` = '".$task_id."' ";
        }else{
            return array();
        }
        $res= $this->query_sql_list($sql);
        $arr=array();
        if(!empty($res)){
            foreach($res as $k=>$v){
                $arr[$k]['id']=$v['task_prize_id'];
            }
        }
        return $arr;
    }


    public function get_id($id){
        $sql='select * from '.$this->table.' where 1 ';
        if(!empty($id)){
            $sql.=" and id=".$id."";
        }else{
            return array();
        }
        return $this->query_sql_one($sql);
    }


}